// 类型判断
/* 
    分为原始值 和引用值
    区分引用值
*/
function type(target) {
    var ret = typeof (target);
    var template = {
        "[object Array]": "array",
        "[object Object]": "object",
        "[object Nmuber]": "number - object",
        "[object Boolean]": "boolean-object",
        "[object String]": "string-object",

    }
    if (target === null) {
        return 'null';
    }
    if (ret == 'object') {
        var str = Object.prototype.toString.call(target);
        return template[str];
    } else {
        return ret;
    }
}

// 数组去重
Array.prototype.unique = function () {
    var temp = {},
        arr = [],
        len = this.length;
    for (var i = 0; i < len; i++) {
        if (!temp[this[i]]) {
            temp[this[i]] = 'abc';
            arr.push(this[i]);
        }
    }
    return arr;
}

// 求滚动条滚动距离

function getScrollOffset() {
    if (window.pageXOffset) {
        return {
            x: window.pageXOffset,
            x: window.pageYOffset
        }
    } else {
        return {
            x : document.body.scrollLeft + document.documentElement.scrollLeft,
            y : document.body.scrollTop + document.documentElement.scrollTop
        }
    }
}


// 获取浏览器窗口大小
function getViewportOffset (){
    if (window.innerWidth) {
        return {
            w : window.innerWidth,
            h : window.innerHeight
        }
    }else{
        if (document.compatMode === 'BackCompat') {
            return {
                w : document.body.clientWidth,
                h : document.body.clientHeight
            }
        }else{
            return {
                w : document.documentElement.clientWidth,
                h : document.documentElement.clientHeight
            }    
        }
    }
}

// 获取元素样式
function getStyle(elem, prop){
    if (window.getComputedStyle) {
        return window.getComputedStyle(elem, null)[prop]
    }else{
        return elem.currentStyle[prop];
    }
}


// 给元素绑定事件  (元素,事件名,方法)
function addEvent(elem, type, handle){
    if (elem.addEventListener) {
        elem.addEventListener(type, handle, false);
    }else if(elem.attachEvent){
        elem.attachEvent('on', + type, function (){
            handle.call(elem);
        })
    }else{
        elem['on' + type] = handle;
    }
}

// 阻止事件冒泡
function stopBubble(event){
    if (event.stopPropagation) {
        event.stopPropagation();
    }else{
        event.cancelBubble = true;
    }
}

//默认事件

function cancelHandler(event){
    if (event.proventDefault) {
        event.preventDefault();
    }else{
        event.returnValue = false;
    }
}


// 异步加载

function loadScript(url,callback){
    var script = document.createElement('script');
    script.type = "text/javascript";
    if (script.readyState) {
        script.onreadystatechange = function(){
            if (script.readyState == 'complete' || script.readyState == 'loaded') {
                callback();
            }
        }
    } else{
        script.onload = function (){
            callback();
        }
    }
    script.src = url;
    document.head.appendChild(script);
}

// 原型链实现继承
let inherit = (function () {
    let F = function () { };
    return function (Target, Origin) {
        F.prototype = Origin.prototype;
        Target.prototype = new F();
        Target.prototype.constuctor = Target;
        Target.prototype.uber = Origin.prototype;
    }
}())